package com.jtyoui.hdfs;

import java.io.IOException;

import com.jtyoui.path.Address;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;

public class ReaderFile {
    public static void main(String[] args) throws IOException {
        System.setProperty("HADOOP_USER_NAME", "hadoop");
        Configuration conf = new Configuration();
        FileSystem fs = FileSystem.get(conf);
        Path path = new Path(Address.HADOOP_PATH.toString() + "/write.txt");
        if (fs.exists(path)) {
            FSDataInputStream fsDataInputStream = fs.open(path);
            FileStatus status = fs.getFileStatus(path);
            byte[] buffer = new byte[Integer.parseInt(String.valueOf(status.getLen()))];
            fsDataInputStream.readFully(0, buffer);
            fsDataInputStream.close();
            fs.close();
            System.out.println(new String(buffer));
        }
    }
}

